package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"github.com/suyuan32/simple-admin-common/orm/ent/mixins"
)

// Combo holds the schema definition for the Combo entity.
type Combo struct {
	ent.Schema
}

// Fields of the Combo.
func (Combo) Fields() []ent.Field {
	return []ent.Field{
		// 商品名称
		field.String("name").
			Comment("商品名称").
			NotEmpty(),
		// 重量
		field.Float("weight").
			Comment("重量 (例如: g)").
			Optional(),
		// 卡路里
		field.Float("calories").
			Comment("卡路里").
			Optional(),
		// 基础价格
		field.Float("price").
			Comment("基础价格"),
		// 销售总数
		field.Int("total_sales").
			Comment("销售总数").
			Default(0),
		field.String("img_addr").
			Comment(" cover's img addr | 封面照片 地址"),
	}
}

// Edges of the Combo.
func (Combo) Edges() []ent.Edge {
	return []ent.Edge{
		// A Combo has many "settings" in the ComboIngredient table.
		// This defines the One-to-Many relationship.
		// The name "product_ingredients" matches the Ref() in the ComboIngredient schema.
		edge.To("combo_ingredients", ComboIngredient.Type),
		// Many-to-Many: a combo can be used by many devices.
		edge.From("devices", Device.Type).Ref("combos"),
	}
}
func (Combo) Mixin() []ent.Mixin {
	return []ent.Mixin{
		mixins.IDMixin{},
	}
}
